package SingletonPattern;

/**
 * Created by HMF on 2021/06/15 11:44
 */

/**
 * 懒汉式单例
 */
public class LazySingleton {
    private static LazySingleton instance = null;

    private LazySingleton() {

    }

    synchronized public static LazySingleton getInstance() { // 在前面加 synchronized 用来解决线程不安全问题
        if (instance == null) {
            instance = new LazySingleton();
        }
        return instance;
    }
}
